<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :rules="rules" :inline="true" label-width="100px" >
      <el-row>
        <el-col :span="6">
          <el-form-item label="体系名称" prop="evaluationSystemName">
            <el-input
              v-model="form.evaluationSystemName"
              placeholder="请输入体系名称"
              clearable
              size="small"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="总分" prop="totalPoints">
            <el-input
              v-model="form.totalPoints"
              oninput="value=value.replace(/[^\d]/g,'')"
              placeholder="请输入总分"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="序号" prop="seqNo">
            <el-input
              v-model="form.seqNo"
              oninput="value=value.replace(/[^\d]/g,'')"
              placeholder="请输入序号"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasRole="['apply']" type="primary" plain size="mini" @click="submitForm">保存</el-button>
      </el-col>
      <el-col :span="1.5" v-show="form.enabledFlag==='1'">
        <el-button v-hasRole="['apply']" type="success" plain size="mini" @click="handleStrat">启用</el-button>
      </el-col>
      <el-col :span="1.5" v-show="form.enabledFlag==='0'">
        <el-button v-hasRole="['apply']" type="danger" plain size="mini" @click="handleStop">停用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasRole="['apply']" type="primary" plain size="mini" @click="addIndicator">添加评估项</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="exportExcel()"
        >导出
        </el-button>
      </el-col>
    </el-row>

    <el-table id="out-table" v-loading="loading"
              :data="applicationItemList"
              border
              @cell-dblclick="handleFocus"
              :span-method="objectSpanMethod"
              :row-class-name="tableRowClassNames"
              ref="report-table"
    >
        <el-table-column :label='"体系："+form.evaluationSystemName'>
          <el-table-column label="一级指标" align="center"  prop="firstSystemIndicator.evaluationIndicatorDescription">
            <template slot-scope="scope">
              <span>{{ scope.row.firstSystemIndicator.evaluationIndicatorDescription }}</span>
              <el-input size="small" oninput="value=value.replace(/[^\d]/g,'')" v-model="scope.row.firstSystemIndicator.evaluationWeight"
                        v-show="scope.row.firstWeightShow"
                        maxlength="3"
                        v-focus
                        @blur="handleMissFocus(scope.$index,scope.row.firstSystemIndicator,'firstEvaluationWeight')"/>
              <span v-show="!scope.row.firstWeightShow">{{ '(' + scope.row.firstSystemIndicator.evaluationWeight + '分)' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="二级指标" align="center"  prop="secondSystemIndicator.evaluationIndicatorDescription">
            <template slot-scope="scope">
              <span>{{ scope.row.secondSystemIndicator.evaluationIndicatorDescription }}</span>
              <el-input size="small" oninput="value=value.replace(/[^\d]/g,'')" v-model="scope.row.secondSystemIndicator.evaluationWeight"
                        v-show="scope.row.secondWeightShow"
                        maxlength="3"
                        v-focus
                        @blur="handleMissFocus(scope.$index,scope.row.secondSystemIndicator,'secondEvaluationWeight')"/>
              <span v-show="!scope.row.secondWeightShow" v-html="calculationtwo(scope.row)"></span>
            </template>
          </el-table-column>
          <el-table-column label="主要观测要素" align="center"  prop="evaluationIndicatorDescription">
            <template slot-scope="scope">
              <span v-html="calculationone(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="考核/协助部门" align="center" width="150" prop="evaluationIndicatorDescription">
            <template slot-scope="scope">
              <span>{{ getdeptName(scope.row) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="观测要素量化考核标准" align="center" width="200" prop="observation">
            <template slot-scope="scope">
             <span v-html="cutout(scope.row.observation)">
          </span>
            </template>
          </el-table-column>
          <el-table-column label="指标权重" align="center" width="150" prop="evaluationWeight">
            <template slot-scope="scope">
              <el-input size="small" oninput="value=value.replace(/[^\d]/g,'')" v-model="scope.row.evaluationWeight"
                        v-show="scope.row.weightShow"
                        maxlength="3"
                        v-focus
                        @blur="handleMissFocus(scope.$index,scope.row,'evaluationWeight')"/>
              <span v-show="!scope.row.weightShow">{{ scope.row.evaluationWeight + '%' }}</span>
            </template>
          </el-table-column>
        </el-table-column>
    </el-table>
    <el-dialog :title="title" :visible.sync="open" width="60%" height="500" append-to-body>
      <el-form :model="indicatorForm" ref="indicatorForm" label-width="80px">
        <el-input
          placeholder="输入关键字进行过滤"
          v-model="filterText">
        </el-input>
        <el-form-item label="评估指标" class="tree">
          <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
          <el-tree
            class="filter-tree"
            :data="menuOptions"
            show-checkbox
            ref="menu"
            node-key="id"
            :check-strictly="false"
            :filter-node-method="filterNode"
            empty-text="加载中，请稍候"
            :props="defaultProps"
          >
            <template slot-scope="{ node, data }">
              <div style="font-size:12px;">
                <span class="overflow-x: auto"> {{ node.label }}</span>
              </div>
            </template>
          </el-tree>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTable">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import math from "@/api/tool/moth";
import FileSaver from "file-saver"
import * as XLSX from 'xlsx/xlsx.mjs';
import XLSXS from "xlsx-style"
import {
  addSystem,
  updateSystem,
  getSystem,
  getSystemIndicatorRange,
  systemIndicatorTreeSelect,
  saveSystemIndicator,
  updateSystemItem,
  checkSystemIndicator
} from "@/api/business/system";
export default {
  name: "SystemApplication",
  props: {
    // 数量限制
    limit: {
      type: Number,
      default: 5,
    },
    // 大小限制(MB)
    fileSize: {
      type: Number,
      default: 5,
    },
    // 文件类型, 例如['png', 'jpg', 'jpeg']
    fileType: {
      type: Array,
      default: () => ["doc", "xls", "ppt", "zip", "pdf"],
    },
    // 是否显示提示
    isShowTip: {
      type: Boolean,
      default: true
    }
  },
  directives: {
    focus: {
      // 指令的定义
      update: function (el) {
        el.querySelector('input').focus();
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.menu.filter(val);
    },
  },
  data() {
    return {
      number: 0,
      printLoading: true,
      // 遮罩层
      loading: true,
      visible: false,
      fileList: [],
      currentRow: null,
      departmentName: "",
      professionName: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      menuExpand: false,
      menuNodeAll: false,
      evaluationDeptOptions: [],
      evaluationProfessionOptions: [],
      evaluationCurriculums: [],
      filterText: '',
      // 菜单列表
      menuOptions: [],
      // 总条数
      total: 0,
      // 评估申请表格数据
      applicationList: [],
      applicationItemList: [],
      isExpandAll: false,
      refreshTable: true,
      multipleSelection: [],
      // 选中数组
      indicatorIds: [],
      indicatorSelection: [],
      evaluationSystemId: null,
      search: '',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        evaluationStandardId: null,
        department: null,
        profession: null,
        curriculum: null,
        firstTime: null,
        person: null,
        description: null,
        appliedStatus: null,
        appliedBy: null,
        auditedBy: null,
        createdAt: null,
        modifiedAt: null,
        submittedAt: null,
        auditedAt: null,
        canceledAt: null
      },
      // 表单参数
      form: {
        evaluationSystemId: null,
        evaluationSystemName: "",
        totalPoints: 100,
        seqNo: null,
        enabledFlag:"1"
      },
      indicatorForm: {evaluationSystemId: null, modifiedCause: null},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      // 表单校验
      rules: {
        evaluationSystemName: [
          {required: true, message: "体系名称不能为空", trigger: "change"}
        ],
        totalPoints: [
          {required: true, message: "总分不能为空", trigger: "blur"}
        ]
      },
      firstItemColumn: [],
      secondItemColumn: []
    };
  },
  created() {
    if (this.$route.params && this.$route.params.evaluationSystemId) {
      this.evaluationSystemId = this.$route.params.evaluationSystemId;
    }
    this.getItemRange(this.evaluationSystemId);
    this.handleUpdate(this.evaluationSystemId);
  },
  computed: {
    // 是否显示提示
    showTip() {
      return this.isShowTip && (this.fileType || this.fileSize);
    },
  },
  methods: {

    exportExcel(excelName) {
      // 为el-table添加一个id：out-table
      // 当el-table使用了fixed时会导出两次数据，所以要先进行判断
      let fix = document.querySelector('.el-table__fixed');
      let wb;
      if (fix) {
        // 如果有fixed，先移除，然后再添加上
        wb = XLSX.utils.table_to_book(document.querySelector("#out-table").removeChild(fix))
        document.querySelector("#out-table").appendChild(fix)
      } else {
        wb = XLSX.utils.table_to_book(document.querySelector("#out-table"))
      }
      // 设置列宽 字号等
      this.setExlStyle(wb['Sheets']['Sheet1']);
      let wbout = XLSXS.write(wb, {
        type: "buffer"
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], {
            type: "application/octet-stream"
          }),
          // 导出的文件名称
          "Data.xlsx"
        )
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    setExlStyle(data) {
      //单元格外侧框线
      const borderAll = {
        top: {
          style: 'thin',
        },
        bottom: {
          style: 'thin'
        },
        left: {
          style: 'thin'
        },
        right: {
          style: 'thin'
        }
      };
      data['!cols'] = [];
      for (let key in data) {
        if (data[key] instanceof Object) {
          // 内容不为空
          if (data[key].v !== '') {
            // 首行
            if (key[1].toString() === "1") {
              data[key].s = {
                alignment: {
                  horizontal: 'center', vertical: 'center'
                },
                font: {name: '微软雅黑', sz: 18, bold: true},
              }
            } else if (key[1].toString() === "2") {
              data[key].s = {
                alignment: {
                  horizontal: 'center', vertical: 'center'
                },
                font: {name: '微软雅黑', sz: 16, bold: true}
              }
            }
              else {
              data[key].s = {
                // 自动换行
                alignment: {
                  horizontal: 'center', vertical: 'center', wrapText: 1
                },
                font: {name: '微软雅黑', sz: 11},
                numFmt: 0
              }
            }
            // 定义列宽
            if (key[1].toString() === "3") {
              let len = String(data[key].v).length
              let w = 0
              switch (String(data[key].v).length) {
                case 3:
                  w = 80;
                  break;
                case 4:
                  w = 100;
                  break;
                case 6:
                  w = 300;
                  break;
                default:
                  w = 200;
              }
              data['!cols'].push({wpx: w});
            }
          }
        }
      }
      return data;
    },
    /** 查询评估指标体系明细列表 */
    getItemRange(evaluationSystemId) {
      this.loading = true;
      let data = {systemId: evaluationSystemId}
      getSystemIndicatorRange(data).then(response => {
        this.applicationItemList = response.data;
        console.log("指标体系明细项", this.applicationItemList)
        //进行行合并处理
        this.getListDataForRowAndColumn(this.applicationItemList)
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        evaluationSystemId: null,
        evaluationSystemName: null,
        totalPoints: 100,
        seqNo: null,
        enabledFlag:"1"
      };
      this.resetForm("form");
    },
    indicatorReset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      this.menuExpand = false,
        this.menuNodeAll = false,
        this.indicatorForm = {
          menuCheckStrictly: true
        };
      this.resetForm("indicatorForm");
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 申请信息查询按钮操作 */
    handleUpdate(evaluationSystemId) {
      getSystem(evaluationSystemId).then(response => {
        console.log("指标体系查询结果", response.data)
        if (response.data) {
          this.form = response.data;
        }
      });
    },
    /** 申请保存提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.evaluationSystemId != null) {
            updateSystem(this.form).then(response => {
              this.getItemRange(this.form.evaluationSystemId);
              this.handleUpdate(this.form.evaluationSystemId);
              this.$modal.msgSuccess("修改成功");
              this.open = false;
            });
          } else {
            addSystem(this.form).then(response => {
              console.log("新增返回id", response.data.evaluationSystemId)
              this.getItemRange(response.data.evaluationSystemId);
              this.handleUpdate(response.data.evaluationSystemId);
              this.$modal.msgSuccess("新增成功");
              this.open = false;
            });
          }
        }
      });
    },
    /** 启用按钮操作 */
    handleStrat() {
      this.$modal.confirm('是否确认启用评估体系？').then(function () {
        return;
      }).then(() => {
        if (this.form.evaluationSystemId == '' || this.form.evaluationSystemId == null) {
          this.$modal.msgError("请先保存评估体系");
          return;
        }
        this.loading = true;
        let data = {systemId: this.form.evaluationSystemId}
        checkSystemIndicator(data).then(response => {
          console.log("校验返回结果", response.data)
          if (response.data.code == "1") {
            this.loading = false;
            this.$modal.msgError(response.data.msg);
            return;
          } else if (response.data.code == "2") {
            this.loading = false;
            this.$modal.msgError(response.data.msg);
            return;
          } else if (response.data.code == "3") {
            this.loading = false;
            this.$modal.msgError(response.data.msg);
            return;
          } else {
            const updateForm = {evaluationSystemId: this.form.evaluationSystemId, enabledFlag:'0'}
            updateSystem(updateForm).then(response => {
              this.$modal.msgSuccess("启用成功");
              this.loading = false;
              this.closeRefreshPage();
            });
          }
        });
      }).catch(() => {
        this.loading = false;
      });

    },
    /** 停用按钮操作 */
    handleStop() {
      this.$modal.confirm('是否确认停用评估体系？').then(function () {
        return;
      }).then(() => {
        if (this.form.evaluationSystemId == '' || this.form.evaluationSystemId == null) {
          this.$modal.msgError("请先保存评估体系");
          return;
        }
          this.loading = true;
          const updateForm = {evaluationSystemId: this.form.evaluationSystemId, enabledFlag:'1'}
          updateSystem(updateForm).then(response => {
            this.$modal.msgSuccess("停用成功");
            this.loading = false;
            this.closeRefreshPage();
          });
      }).catch(() => {
        this.loading = false;
      });

    },
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 多选框选中数据
    indicatorSelectionChange(selection) {
      this.indicatorIds = selection.map(item => item.evaluationIndicatorId)
      this.indicatorSelection = selection
    },
    /** 添加评估直指标按钮操作 */
    addIndicator() {
      if (this.form.evaluationSystemId == '' || this.form.evaluationSystemId == null) {
        this.$modal.msgError("请先保存体系");
        return;
      }
      this.indicatorReset();
      this.open = true;
      this.title = "添加指标项";
      systemIndicatorTreeSelect(this.form.evaluationSystemId).then(response => {
        this.menuOptions = response.indicator;
        let checkedKeys = response.checkedKeys;
        console.log("返回选中", checkedKeys)
        checkedKeys.forEach((v) => {
          this.$nextTick(() => {
            this.$refs.menu.setChecked(v, true, false);
          })
        })
      });
    },
    submitTable() {
      //过去选中的指标项
      const indicatorIds = this.getMenuAllCheckedKeys();
      console.log("获取添加指标项", indicatorIds)
      let data = {systemId: this.form.evaluationSystemId, indicatorIds: indicatorIds}
      saveSystemIndicator(data).then(response => {
        this.$modal.msgSuccess("添加成功");
        this.open = false;
        this.getItemRange(this.form.evaluationSystemId);
        this.handleUpdate(this.form.evaluationSystemId);
      });
    },
    getMenuAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.menu.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('evaluation/application/export', {
        ...this.queryParams
      }, `application_${new Date().getTime()}.xlsx`)
    },
    /** 打开行内编辑 */
    handleFocus(index, column) {
      debugger
      if(this.form.enabledFlag==="0"){
        this.$modal.msgWarning("已启用的指标体系不能变更指标明细，请先停用");
        return;
       }
        switch (column.property) {
          case "firstSystemIndicator.evaluationIndicatorDescription":
            index.firstWeightShow = true;
            break;
          case "secondSystemIndicator.evaluationIndicatorDescription":
            index.secondWeightShow = true;
            break;
          case "evaluationWeight":
            index.weightShow = true;
            break;
        }
    },
    handleMissFocus(index, row, columnName) {
      const updateForm = {
        evaluationSystemIndicatorId: row.evaluationSystemIndicatorId,
        evaluationWeight: null
      }
      if (columnName === 'firstEvaluationWeight') {
        updateForm.evaluationWeight = row.evaluationWeight
        if (updateForm.evaluationWeight == '' || updateForm.evaluationWeight == null) {
          this.$modal.msgError("分数不能为空");
          return;
        }
        //一级二级重新计算指标评分
        updateSystemItem(updateForm).then(response => {
          this.applicationItemList[index].weightShow = false;
          this.applicationItemList[index].firstWeightShow = false;
          this.applicationItemList[index].secondWeightShow = false;
          //该父级下所有子集重新计算评分
          this.applicationItemList.forEach((item, index) => {
            if (item.firstSystemIndicator.evaluationSystemIndicatorId == row.evaluationSystemIndicatorId) {
              //先更新子集的父级的分数，不然计算出来的分值不正确
              item.firstSystemIndicator.evaluationWeight = row.evaluationWeight
            }
          });
        });
      } else if (columnName === 'secondEvaluationWeight') {
        updateForm.evaluationWeight = row.evaluationWeight
        if (updateForm.evaluationWeight == '' || updateForm.evaluationWeight == null) {
          this.$modal.msgError("占比不能为空");
          return;
        }
        //一级二级重新计算指标评分
        console.log("编辑入参", updateForm)
        updateSystemItem(updateForm).then(response => {
          this.applicationItemList[index].weightShow = false;
          this.applicationItemList[index].firstWeightShow = false;
          this.applicationItemList[index].secondWeightShow = false;
          //该父级下所有子集重新计算评分
          this.applicationItemList.forEach((item, index) => {
            if (item.secondSystemIndicator.evaluationSystemIndicatorId == row.evaluationSystemIndicatorId) {
              //先更新子集的父级的占比，不然计算出来的分值不正确
              item.secondSystemIndicator.evaluationWeight = row.evaluationWeight
            }
          });
        });
      } else if (columnName === 'evaluationWeight') {
        updateForm.evaluationWeight = row.evaluationWeight
        if (updateForm.evaluationWeight == '' || updateForm.evaluationWeight == null) {
          this.$modal.msgError("权重不能为空");
          return;
        }
        updateSystemItem(updateForm).then(response => {
          this.applicationItemList[index].weightShow = false;
          this.applicationItemList[index].firstWeightShow = false;
          this.applicationItemList[index].secondWeightShow = false;
        });
      }
    },
    // 树权限（展开/折叠）
    handleCheckedTreeExpand(value, type) {
      if (type == 'menu') {
        let treeList = this.menuOptions;
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
        }
      }
    },
    // 树权限（全选/全不选）
    handleCheckedTreeNodeAll(value, type) {
      if (type == 'menu') {
        this.$refs.menu.setCheckedNodes(value ? this.menuOptions : []);
      }
    },
    // 树权限（父子联动）
    handleCheckedTreeConnect(value, type) {
      if (type == 'menu') {
        this.form.menuCheckStrictly = value ? true : false;
      }
    },
    /**  评估明细项表格一级二级合并行操作开始 **/
    //判断需要合并行，进行数组组装
    getListDataForRowAndColumn(data) {
      let self = this;
      self.firstItemColumn = [];
      self.secondItemColumn = [];
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          // 如果是第一条记录（即索引是0的时候），向数组中加入１
          self.firstItemColumn.push(1);
          self.pos = 0;
          self.secondItemColumn.push(1);
          self.posT = 0;
        } else {
          if (data[i].firstSystemIndicator.evaluationSystemIndicatorId === data[i - 1].firstSystemIndicator.evaluationSystemIndicatorId) {
            // 如果storeName相等就累加，并且push 0
            self.firstItemColumn[self.pos] += 1
            self.firstItemColumn.push(0)
            if (data[i].secondSystemIndicator.evaluationSystemIndicatorId === data[i - 1].secondSystemIndicator.evaluationSystemIndicatorId) {
              // 如果roomName相等就累加，并且push 0
              self.secondItemColumn[self.posT] += 1
              self.secondItemColumn.push(0)
            } else {
              self.secondItemColumn.push(1)
              self.posT = i
            }
          } else {
            // 不相等push 1
            self.firstItemColumn.push(1)
            self.pos = i;
            self.secondItemColumn.push(1)
            self.posT = i
          }
        }
      }
    },
    //行合并
    objectSpanMethod({row, column, rowIndex, columnIndex}) {
      let self = this
      if (columnIndex === 0) {
        if (self.firstItemColumn[rowIndex]) {
          let rowNum = self.firstItemColumn[rowIndex];
          return {
            rowspan: rowNum,
            colspan: rowNum > 0 ? 1 : 0
          }
        }
        return {
          rowspan: 0,
          colspan: 0
        }
      }
      if (columnIndex === 1) {
        if (self.secondItemColumn[rowIndex]) {
          let roomNum = self.secondItemColumn[rowIndex];
          return {
            rowspan: roomNum,
            colspan: roomNum > 0 ? 1 : 0
          }
        }
        return {
          rowspan: 0,
          colspan: 0
        }
      }
    },
    /**  评估明细项表格一级二级合并行操作结束 **/
    cutout(cellValue) {
      return cellValue.replaceAll('|', '<br/>')
    },
    calculationone(row) {
      return row.evaluationIndicatorDescription + '(' + math.multiply(row.firstSystemIndicator.evaluationWeight * row.secondSystemIndicator.evaluationWeight * row.evaluationWeight,0.0001)+ '分)'
    },
    calculationtwo(row) {
      return '(' + row.secondSystemIndicator.evaluationWeight + '%)' + '(' +math.multiply(row.firstSystemIndicator.evaluationWeight * row.secondSystemIndicator.evaluationWeight,0.01) + '分)'
    },
    getdeptName(row) {
      var evaluationDeptName=row.evaluationDeptName ? row.evaluationDeptName+ '/' : ""
      var assistDeptName=row.assistDeptName ? row.assistDeptName : ""
      return evaluationDeptName+assistDeptName;
    },
    /**行字体颜色 */
    tableRowClassNames(val) {
      if (val.row.isRed) {
        return 'red-row';
      } else {
        return '';
      }
    },
    /** 关闭当前页并刷新首页 */
    closeRefreshPage() {
      const obj = {path: "/evaluation/system", query: {refresh: true}};
      this.$tab.closeOpenPage(obj);
    }
  },
};

</script>
<style lang="scss">
.tree {
  .el-tree-node {
    white-space: normal;

    .el-tree-node__content {
      height: 100%;
      align-items: start;
    }
  }
}

table {
  font-family: Arial, sans-serif;
  font-size: 14px;
  background-color: #f0f2f5;
  border-collapse: collapse;
  color: #454545;
  table-layout: auto;
  width: 100%;
  text-align: center;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  border-bottom-color: #dadcde;

  thead {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #dadcde;
    line-height: 40px;
    font-weight: bold;
    color: #454c70;
  }

  tr {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #dadcde;
    line-height: 23px;
  }

  td {
    padding: 5px 10px;
    font-size: 14px;
    font-family: Verdana;
    width: 100px;
    word-break: break-all; // 元素换行
  }

  // 斑马纹效果stripe
  //tr:nth-child(even) {
  //  background: #F5F7F9;
  //}
  //
  //tr:nth-child(odd) {
  //  background: #FFF;
  //}
}

.el-table .red-row {
  color: red;
}
</style>
<style media="print" lang="scss">
@page {
  size: auto;
  margin: 3mm;
}

@media print {
  html {
    background-color: #ffffff;
    height: auto;
    margin: 0px;
  }

  body {
    border: solid 1px #ffffff;
    margin: 10mm 15mm 10mm 15mm;
  }
  table {
    table-layout: auto !important;
  }

  .el-table__header-wrapper .el-table__header {
    width: 100% !important;
    border: solid 1px #f2f2f2;
  }
  .el-table__body-wrapper .el-table__body {
    width: 100% !important;
  }
  #pagetable table {
    table-layout: fixed !important;
  }
}
</style>
